﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model DepartmentWork.Model.EmpAuthorityViewModel
<script>
    function DelAuth(authorityId)
    {
        if (!confirm("请确认是否删除该权限？"))
        {
            return false;
        }
        window.location.href = '@Url.Action("DelAuthorityRole", "Authority", new { area = "SystemSettingArea" })' + '?authorityId=' + authorityId;
    }
</script>
<div class="page-header">
    <div class="pull-left">
        <ol class="breadcrumb visible-sm visible-md visible-lg">
            <li><a href="@Url.Action("Index", "Home", new { area = "" })"><i class="icon fa fa-home"></i>主页</a></li>
            <li><a href="#"><i class="fa fa-envelope"></i>系统设置</a></li>
            <li class="active"><a href="#"><i class="fa fa-envelope"></i>权限管理</a></li>

        </ol>
    </div>
</div>

<div class="row">
    <div class="col-lg-12">
        <div class="panel">
            <div class="panel-heading bk-bg-primary">
                <h6><i class="fa fa-table red"></i><span style="font-size: medium" class="break">权限列表</span></h6>
@*                <div class="panel-actions">
                    <a data-toggle="modal" data-target="#CreateAuthorityModal" class="bk-margin-5 btn btn-default  btn-sm" style="background-color: #ECEDF0">&nbsp;&nbsp;新增权限&nbsp;&nbsp;</a>
                </div>*@
            </div>
            <div class="panel-body">
                <div class="tabs">
                    <ul class="nav nav-tabs">
                        <li class="active"></li>
                    </ul>
                    <div class="tab-content">
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered bootstrap-datatable datatable">
                                    <thead>
                                        <tr>
                                            <th style="width: 30%">权限名称</th>
                                            <th style="width: 50%">权限说明</th>
                                            <th style="width: 20%">操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @{
                                            for (int i = 0; i < this.Model.ListOfAuthority.Count; i++)
                                            {
                                                var item = this.Model.ListOfAuthority[i];
                                                <tr>
                                                    <td>@item.AUTHORITY_TITLE</td>
                                                    <td>@item.AUTHORITY_ILLUSTRATE</td>
                                                    <td>
                                                        <button type="button" class="bk-margin-5 btn btn-info btn-xs">编 辑</button>
                                                        &nbsp;
                                                        <a onclick="GetAuthorityToRole('@item.AUTHORITY_ID')" data-toggle="modal" data-target="#ControlAuthorityRoleModal"> <input type="button" class="bk-margin-5 btn btn-default btn-xs" value="匹配权限" /></a>
                                                        &nbsp;
                                                       @* <button type="button" onclick="DelAuth('@item.AUTHORITY_ID')"  class="bk-margin-5 btn btn-danger btn-xs">删 除</button>*@
                                                    </td>
                                                </tr>
                                            }
                                        }
                                    </tbody>
                                </table>
                                                     <div class="bk-margin-5 btn-group" style="float: right">
                          @Html.ShowPageNavigate((int)ViewData["pageIndex"], (int)ViewData["pageSize"], (int)ViewData["total"], (string)ViewBag.ProjectId)
                     </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>



<!-- 详情模态框（Modal） -->
<script>
    function SubmitCreate()
    {

        var message = "";

        alert($("#CreateAuthorityModal #tb_AuthorityName").val().length);

        if ($("#CreateAuthorityModal #tb_AuthorityName").val().length > 30)
        {
            message += "· 权限名称输入的过长";
        }

        if ($("#CreateAuthorityModal #tb_CreateAuthorityContext").val().length > 100)
        {
            message += "· 权限描述输入的过长";
        }

        if (message != "")
        {
            $("#lb_CheckCreateAuthorityMessage").html(message);
            $("#div_CheckCreateAuthorityMessage").css("display", "block");
            return false;
        }
        else
        {
            $("#lb_CheckCreateAuthorityMessage").html("");
            $("#div_CheckCreateAuthorityMessage").css("display", "none");
            $("#CreateAuthorityModal #frm_CreateAuthority").submit();
        }
    }
</script>

<div class="modal fade" id="CreateAuthorityModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">新增权限
                </h4>
                <form method="POST" id="frm_CreateAuthority" action="@Url.Action("CreateAuthority", "Authority", new { area = "SystemSettingArea" })">
                    <div class="alert alert-danger" id="div_CheckCreateAuthorityMessage" style="display: none">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <strong>
                            <label id="lb_CheckCreateAuthorityMessage"></label>
                        </strong>
                    </div>

                    <div class="modal-body">

                        <div class="row">
                            <label class="col-md-3 control-label" for="text-input">权限名称：</label>
                            <div class="col-md-9">
                                <input id="tb_AuthorityName" name="tb_AuthorityName" style="border-color: cornflowerblue" class="form-control" placeholder="Text" type="text">
                            </div>
                        </div>
                        <hr />

                        <div class="row">
                            <label class="col-md-3 control-label" for="text-input">权限描述：</label>
                            <div class="col-md-9">
                                <textarea id="tb_CreateAuthorityContext" name="tb_CreateAuthorityContext" class="form-control" rows="3"></textarea>
                            </div>
                        </div>
                        <hr />
                    </div>
                </form>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        关闭
                    </button>
                    <input type="button" onclick="SubmitCreate()" class="btn btn-primary" value="新增" />
                </div>

            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal -->
    </div>


</div>




<script>
    function GetAuthorityToRole(authorityId) {
        $("#ControlAuthorityRoleModal #hid_AuthorityId").val(authorityId);
        $.ajax({
            type: "POST",
            url: '@Url.Action("GetAuthorityRoleInfo", "Authority", new {area = "SystemSettingArea"})',
            data: "authorityId=" + authorityId,
            error: function() {
                alert('服务器出现异常');
            },
            success: function(data) {
                $("#ControlAuthorityRoleModal").find("input[type='checkbox']").each(function() {
                    if ($(this).attr("id") == "ck_" + data["AUTHORITY_ID"]) {
                        $(this).attr("checked", "checked");
                    }
                });
            }
        });
    }

    function SubmitControlAuthorityRole() {
        $("#frm_ControllerAuthorityRole").submit();
    }

</script>

<div class="modal fade" id="ControlAuthorityRoleModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">分配权限至角色
                </h4>
                <form method="POST" id="frm_ControllerAuthorityRole" action="@Url.Action("BindingAuthorityRole", "Authority", new { area = "SystemSettingArea" })">
                    <div class="alert alert-danger" id="div_ControllerAuthorityRoleMessage" style="display: none">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <strong>
                            <label id="lb_ControllerAuthorityRoleyMessage"></label>
                        </strong>
                    </div>

                    <div class="modal-body">
                        <input type="hidden" name="hid_AuthorityId" id="hid_AuthorityId"/>
                        <div class="row">
                            <label class="col-md-3 control-label" for="text-input">分配：</label>
                            <div class="col-md-9">
                                @{
                                    for (int i = 0; i < this.Model.ListOfRole.Count(); i++)
                                    {
                                    <input  id="ck_@Model.ListOfRole[i].ROLE_ID" name="ck_RoleId" value="@this.Model.ListOfRole[i].ROLE_ID"  type="checkbox" />
                                    <label for="lb_EditRoleId">@this.Model.ListOfRole[i].ROLE_NAME</label>
                                    @:&nbsp;&nbsp;
                                        if (i % 2 != 0)
                                        {
                                    <br />
                                        }
                                    }

                                }

                            </div>
                        </div>
                        <hr />
                    </div>
                </form>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        关闭
                    </button>
                    <input type="button" onclick="SubmitControlAuthorityRole()" class="btn btn-primary" value="绑定" />
                </div>

            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal -->
    </div>


</div>
